HAL LTDC type migration

This section provides information about the HAL LTDC type migration.

HAL LTDC callback ID type definition

HAL1

HAL2

typedef enum
{
  HAL_LTDC_ERROR_CB_ID,
  HAL_LTDC_LINE_EVENT_CB_ID,
  HAL_LTDC_MSPDEINIT_CB_ID,
  HAL_LTDC_MSPINIT_CB_ID,
  HAL_LTDC_RELOAD_EVENT_CB_ID
} HAL_LTDC_CallbackIDTypeDef;
  • Removed in HAL2 : the callback registration is managed by dedicated functions for each LTDC event. For more details, see : HAL LTDC register callback functions

  • HAL_LTDC_MSPINIT_CB_ID and HAL_LTDC_MSPDEINIT_CB_ID are removed because the functions HAL_LTDC_MspInit() and HAL_LTDC_MspDeInit() are removed.

Related concepts:


HAL LTDC callback type definition

HAL1

HAL2

pLTDC_CallbackTypeDef
hal_ltdc_cb_t

HAL LTDC state type definition

HAL1

HAL2

In HAL1, the LTDC is ready for use after initialization and layer configuration, both resulting in the HAL_LTDC_STATE_READY state.

typedef enum
{
  HAL_LTDC_STATE_RESET,
  HAL_LTDC_STATE_READY,

  HAL_LTDC_STATE_BUSY,
  HAL_LTDC_STATE_TIMEOUT,
  HAL_LTDC_STATE_ERROR
} HAL_LTDC_StateTypeDef;

In HAL2, two separate state machines are provided: one for the LTDC peripheral and one for each layer. For the LTDC to be ready for use; it must be initialized resulting in HAL_LTDC_STATE_INIT state, configured resulting in HAL_LTDC_STATE_CONFIGURED state and started resulting in HAL_LTDC_STATE_ACTIVE state. Then layer must be configured resulting in HAL_LTDC_LAYER_STATE_CONFIGURED state.

typedef enum
{
  HAL_LTDC_STATE_RESET,
  HAL_LTDC_STATE_INIT,
  HAL_LTDC_STATE_CONFIGURED,
  HAL_LTDC_STATE_ACTIVE
} hal_ltdc_state_t;

typedef enum
{
  HAL_LTDC_LAYER_STATE_RESET,
  HAL_LTDC_LAYER_STATE_CONFIGURED
} hal_ltdc_layer_state_t;

Related concepts:


HAL LTDC color type definition

HAL1

HAL2

In HAL1, the background color is set using the LTDC_ColorTypeDef structure:
  • LTDC background color: Defined by the Backcolor field in LTDC_InitTypeDef structure for overall LTDC background color.

  • LTDC layer background color: Defined by the Backcolor field in LTDC_LayerCfgTypeDef structure for each specific LTDC layer.

typedef struct
{
  uint8_t Blue;

  uint8_t Green;

  uint8_t Red;

  uint8_t Reserved;
} LTDC_ColorTypeDef;
In HAL2, the LTDC_ColorTypeDef structure is removed, along with the following changes:
  • LTDC background color: The background color is set as default unless changed via HAL_LTDC_SetBackgroundColor(const hal_ltdc_handle_t *hltdc, uint32_t rgb888_color) where rgb888_color represents the uint32 background color in RGB format.

  • LTDC layer background color: Set using the uint32 background_color_argb8888 field in hal_ltdc_layer_config_t or changed via HAL_LTDC_SetLayerBackgroundColor(hal_ltdc_handle_t *hltdc, hal_ltdc_layer_t layer, uint32_t color) function where color represents the uint32 background color in RGB format.

HAL1

HAL2

LTDC Background color

LTDC_HandleTypeDef hltdc;
LTDC_ColorTypeDef Color;

/* Background color configuration */
Color.Blue  = 0x00;
Color.Green = 0x00;
Color.Red   = 0x00;


/* LTDC Configuration */
hltdc.Init.HSPolarity = LTDC_HSPOLARITY_AL;
hltdc.Init.VSPolarity = LTDC_VSPOLARITY_AL;
hltdc.Init.DEPolarity = LTDC_DEPOLARITY_AL;
hltdc.Init.PCPolarity = LTDC_PCPOLARITY_IPC;
hltdc.Init.HorizontalSync     = 3;
hltdc.Init.VerticalSync       = 3;
hltdc.Init.AccumulatedHBP     = 11;
hltdc.Init.AccumulatedVBP     = 11;
hltdc.Init.AccumulatedActiveW = 811;
hltdc.Init.AccumulatedActiveH = 491;
hltdc.Init.TotalWidth         = 819;
hltdc.Init.TotalHeigh         = 499;
hltdc.Init.Backcolor.Blue     = Color.Blue;
hltdc.Init.Backcolor.Green    = Color.Green;
hltdc.Init.Backcolor.Red      = Color.Red;

HAL_LTDC_Init(&hltdc);



/* To change the LTDC background color */
hltdc.Init.Backcolor.Blue  = 0xFF;
hltdc.Init.Backcolor.Green = 0xFF;
hltdc.Init.Backcolor.Red   = 0xFF;
HAL_LTDC_Init(&hltdc);
hal_ltdc_handle_t  hltdc;






hal_ltdc_config_t ltdc_cfg;

/* LTDC configuration */
ltdc_cfg.hsync_polarity       = HAL_LTDC_HSYNC_POLARITY_LOW;
ltdc_cfg.vsync_polarity       = HAL_LTDC_VSYNC_POLARITY_LOW;
ltdc_cfg.data_enable_polarity = HAL_LTDC_DATA_ENABLE_POLARITY_LOW;
ltdc_cfg.pixel_clock_polarity = HAL_LTDC_PIXEL_CLOCK_POLARITY_LOW;
ltdc_cfg.hsync           = 3;
ltdc_cfg.vsync           = 3;
ltdc_cfg.h_back_porch    = 11;
ltdc_cfg.v_back_porch    = 11;
ltdc_cfg.active_width    = 811;
ltdc_cfg.active_height   = 491;
ltdc_cfg.h_front_porch   = 819;
ltdc_cfg.v_front_porch   = 499;




HAL_LTDC_Init(&hltdc, HAL_LTDC);
HAL_LTDC_SetConfig(&hltdc, &ltdc_cfg);
HAL_LTDC_Start(&hltdc,HAL_LTDC_IT_NONE);

/* To change the default LTDC background color */
HAL_LTDC_SetBackgroundColor(&hltdc, 0xFFFFFF);

HAL1

HAL2

LTDC Layer Background color

/* LTDC Layer configuration */
LTDC_LayerCfgTypeDef pLayerCfg;

pLayerCfg.WindowX0 = 0;
pLayerCfg.WindowX1 = 485;
pLayerCfg.WindowY0 = 100;
pLayerCfg.WindowY1 = 330;
pLayerCfg.PixelFormat     = LTDC_PIXEL_FORMAT_ARGB4444;
pLayerCfg.FBStartAdress   = 0x00;
pLayerCfg.ImageWidth      = 480;
pLayerCfg.ImageHeight     = 272;
pLayerCfg.Alpha           = 255;
pLayerCfg.BlendingFactor1 = LTDC_BLENDING_FACTOR1_CA;
pLayerCfg.BlendingFactor2 = LTDC_BLENDING_FACTOR2_CA;
pLayerCfg.Alpha0          = 0x00;
pLayerCfg.Backcolor.Blue  = 0x00;
pLayerCfg.Backcolor.Green = 0x00;
pLayerCfg.Backcolor.Red   = 0x00;

HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 1);


/* To change the LTDC layer background color */
pLayerCfg.Backcolor.Blue  = 0xFF;
pLayerCfg.Backcolor.Green = 0xFF;
pLayerCfg.Backcolor.Red   = 0xFF;
HAL_LTDC_ConfigLayer(&hltdc, &pLayerCfg, 1);
/* LTDC Layer configuration */
hal_ltdc_layer_config_t layer_cfg;

layer_cfg.window_x0 = 0;
layer_cfg.window_x1 = 485;
layer_cfg.window_y0 = 100;
layer_cfg.window_y1 = 330;
layer_cfg.frame_buffer.pixel_format = HAL_LTDC_PIXEL_FORMAT_ARGB4444;
layer_cfg.frame_buffer.address      = 0x00;
layer_cfg.frame_buffer.width        = 480;
layer_cfg.frame_buffer.height       = 272;
layer_cfg.alpha                     = 255;
layer_cfg.blending_factor1          = HAL_LTDC_BLENDING_FACTOR1_CA;
layer_cfg.blending_factor2          = HAL_LTDC_BLENDING_FACTOR2_1_MINUS_CA;
layer_cfg.background_color_argb8888 = 0x00;




HAL_LTDC_SetConfigLayer(&hltdc, HAL_LTDC_LAYER_1, &layer_cfg);
HAL_LTDC_ForceReload(&hltdc, HAL_LTDC_RELOAD_IMMEDIATE);

/* To change the LTDC layer background color */
HAL_LTDC_SetLayerBackgroundColor(&hltdc, HAL_LTDC_LAYER_1, 0xFFFFFF);
HAL_LTDC_ForceReload(&hltdc, HAL_LTDC_RELOAD_IMMEDIATE);

Related concept:


HAL LTDC handle type definition

HAL1

HAL2

LTDC_HandleTypeDef;
hal_ltdc_handle_t

Related concepts:


HAL LTDC initialization type definition

The Backcolor field in the LTDC_InitTypeDef structure is removed and is being managed independently by the HAL_LTDC_SetBackgroundColor() function in HAL2.

HAL1

HAL2

 typedef struct
{
  uint32_t            HSPolarity;
  uint32_t            VSPolarity;
  uint32_t            DEPolarity;
  uint32_t            PCPolarity;
  uint32_t            HorizontalSync;
  uint32_t            VerticalSync;
  uint32_t            AccumulatedHBP;
  uint32_t            AccumulatedVBP;
  uint32_t            AccumulatedActiveW;
  uint32_t            AccumulatedActiveH;
  uint32_t            TotalWidth;
  uint32_t            TotalHeigh;


  LTDC_ColorTypeDef   Backcolor;
} LTDC_InitTypeDef;
 typedef struct
{
  hal_ltdc_hsync_polarity_t       hsync_polarity;
  hal_ltdc_vsync_polarity_t       vsync_polarity;
  hal_ltdc_data_enable_polarity_t data_enable_polarity;
  hal_ltdc_pixel_clock_polarity_t pixel_clock_polarity;
  uint32_t                        hsync;
  uint32_t                        vsync;
  uint32_t                        h_back_porch;
  uint32_t                        v_back_porch;
  uint32_t                        active_width;
  uint32_t                        active_height;
  uint32_t                        h_front_porch;
  uint32_t                        v_front_porch;
  } hal_ltdc_config_t;

  use instead : HAL_LTDC_SetBackgroundColor()

Related concepts:


HAL LTDC layer configuration type definition

The Alpha0 field is being managed along side with Backcolor by the uint32 background_color_argb8888 field in HAL2.

HAL1

HAL2

 typedef struct
{
  uint32_t WindowX0;
  uint32_t WindowX1;
  uint32_t WindowY0;
  uint32_t WindowY1;
  uint32_t Alpha;
  uint32_t BlendingFactor;
  uint32_t BlendingFactor2;
  uint32_t FBStartAdress;
  uint32_t ImageWidth;
  uint32_t ImageHeight;
  uint32_t PixelFormat;

  uint32_t Alpha0;
  LTDC_ColorTypeDef   Backcolor;
} LTDC_LayerCfgTypeDef;
 typedef struct
{
  uint16_t                    window_x0;
  uint16_t                    window_x1;
  uint16_t                    window_y0;
  uint16_t                    window_y1;
  uint8_t                     alpha;
  hal_ltdc_blending_factor1_t blending_factor1;
  hal_ltdc_blending_factor2_t blending_factor2;
  hal_ltdc_frame_buffer_t     frame_buffer;




  uint32_t                    background_color_argb8888;

} hal_ltdc_layer_config_t;

typedef struct
{
  uint32_t                address;
  uint32_t                width;
  uint32_t                height;
  hal_ltdc_pixel_format_t pixel_format;
} hal_ltdc_frame_buffer_t;

Related concepts: